package com.wu.controller;/**
 * @author sun
 * @date 2022/3/27 - 22:42
 */

import com.wu.pojo.MaterialsValues;
import com.wu.service.MaterialsValuesService;
import com.wu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author 孙
 * @date 2022/3/27 22:42
 * @version 1.0
 */
@RestController
@Api(tags="MaterialsValues模块")
@CrossOrigin
@RequestMapping("materialsValues")
public class MaterialsValuesController {
    @Autowired
    private MaterialsValuesService materialsValuesService;
    @PostMapping("/insertMaterialsValues")
    @ApiOperation(value="增加MaterialsValues")
    public R insertMaterialsValues(@RequestBody MaterialsValues materialsValues){
        try {
            materialsValuesService.insertSelective(materialsValues);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteMaterialsValues/{id}")
    @ApiOperation(value="删除MaterialsValues")
    public R deleteMaterialsValues(Integer id){
        try {
            materialsValuesService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateMaterialsValues")
    @ApiOperation(value="更新MaterialsValues")
    public R updateMaterialsValues(@RequestBody MaterialsValues materialsValues){
        try {
            materialsValuesService.updateByPrimaryKeySelective(materialsValues);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findMaterialsValues")
    @ApiOperation(value="查询MaterialsValuesList")
    public R findMaterialsValues(MaterialsValues materialsValues){
        try {
            List<MaterialsValues> list= materialsValuesService.findMaterialsValues(materialsValues);
            return R.ok().data("materialsValuesList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findMaterialsValuesById/{id}")
    @ApiOperation(value="通过id查询MaterialsValues")
    public R findMaterialsValues(Integer id){
        try {
            MaterialsValues materialsValues= materialsValuesService.selectByPrimaryKey(id);
            return R.ok().data("materialsValues",materialsValues);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}
